package demoMod.stsconsole.commands;

import demoMod.stsconsole.enums.AvailableLanguage;
import demoMod.stsconsole.enums.ErrType;
import demoMod.stsconsole.helpers.LocalizedStrings;
import demoMod.stsconsole.settings.ConsoleSettings;

import java.util.List;
import java.util.Locale;
import java.util.Scanner;

public class Settings extends AbstractCommand {
    @Override
    public void execute(String[] args, Scanner sc) {
        if (args.length == 0) {
            this.errMsg(ErrType.WRONG_ARGUMENT);
            return;
        }
        switch (args[0]) {
            case "language":
                if (args.length != 2 && args.length != 1) {
                    this.errMsg(ErrType.WRONG_ARGUMENT);
                    return;
                }
                if (args.length == 2) {
                    boolean t = false;
                    for (AvailableLanguage language : AvailableLanguage.values()) {
                        if (language.name().equalsIgnoreCase(args[1])) {
                            ConsoleSettings.language = args[1].toLowerCase(Locale.ROOT);
                            LocalizedStrings.initialize();
                            List<String> cmdStrings = LocalizedStrings.getCommandStrings("Settings");
                            System.out.println(cmdStrings.get(0) + ConsoleSettings.language);
                            t = true;
                            break;
                        }
                    }
                    if (!t) this.errMsg(ErrType.UNSUPPORTED_LANGUAGE);
                } else {
                    List<String> cmdStrings = LocalizedStrings.getCommandStrings("Settings");
                    System.out.println(cmdStrings.get(1));
                    for (AvailableLanguage language : AvailableLanguage.values()) {
                        System.out.println(language);
                    }
                }
                break;
            default:
                this.errMsg(ErrType.WRONG_ARGUMENT);
                break;
        }
    }

    @Override
    public boolean requiredPrompt(String currentPrompt) {
        return true;
    }
}
